package com.example.administrator.myapplication;

import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.Toast;

public class TreeActivity extends AppCompatActivity {

    private RadioGroup radioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tree);
        initView();
        initData();
        initEvent();
    }
    private  void initView(){
        radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
    }
    private  void  initData(){

    }
    private void initEvent(){
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                Toast.makeText(TreeActivity.this,checkedId+"",Toast.LENGTH_SHORT).show();
                if(checkedId==R.id.radioBtn1){
                    Toast.makeText(TreeActivity.this,"您选择了男生",Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(TreeActivity.this,"您选择了女生",Toast.LENGTH_SHORT).show();
                }

//   高版本允许使用方式             if (checkedId==1){
//
//                }
            }
        });
    }
}
